//
//  XJStatusCell.m
//  weiboOC
//
//  Created by 徐绩 on 16/4/22.
//  Copyright © 2016年 ayumi. All rights reserved.
//

#import "XJStatusCell.h"
#import "XJStatusToolBar.h"

@implementation XJStatusCell

-(void)setStatusViewModel:(XJStatusViewModel *)statusViewModel{

    self.originalView.statusViewModel = statusViewModel;
    
    [self.toolBarTopCons uninstall];
    if (statusViewModel.statusModel.retweeted_status) {
        
        //如果存在转发微博,显示并赋值数据,更改约束
        self.retWeetView.hidden = NO;
        self.retWeetView.statusViewModel = statusViewModel;
        [self.toolBar updateConstraints:^(MASConstraintMaker *make) {
            
          self.toolBarTopCons = make.top.equalTo(self.retWeetView.bottom);
        }];
        
    }else{
    
        self.retWeetView.hidden = YES;
        [self.toolBar updateConstraints:^(MASConstraintMaker *make) {
            
           self.toolBarTopCons = make.top.equalTo(self.originalView.bottom);
        }];
    }
}
-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{

    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        
        [self setupUI];
    }
    return self;
}

-(void)setupUI{
    
    self.contentView.backgroundColor = [UIColor colorWithWhite:252/255.0 alpha:1];
    self.selectionStyle = UITableViewCellSelectionStyleNone;
    
    XJOriginalView *originalView = [[XJOriginalView alloc]init];
    self.originalView = originalView;
    [self.contentView addSubview:originalView];
    
    XJStatusToolBar *toolBar = [[XJStatusToolBar alloc]init];
    self.toolBar = toolBar;
    [self.contentView addSubview:toolBar];
    
    XJRetWeetView *retWeetView = [[XJRetWeetView alloc]init];
    self.retWeetView = retWeetView;
    [self.contentView addSubview:retWeetView];
    retWeetView.hidden = YES;
    
    [originalView makeConstraints:^(MASConstraintMaker *make) {
        
        make.leading.trailing.equalTo(self.contentView);
        make.top.equalTo(self.contentView).offset(statusCellMargin);
    }];
    
    [toolBar makeConstraints:^(MASConstraintMaker *make) {
        
        make.leading.trailing.equalTo(self.contentView);
        self.toolBarTopCons = make.top.equalTo(retWeetView.bottom);
        //NSLog(@"%@",self.toolBarTopCons);
        make.height.equalTo(StatusCellBottomViewH);
    }];
    
    [retWeetView makeConstraints:^(MASConstraintMaker *make) {
        
        make.leading.trailing.equalTo(originalView);
        make.top.equalTo(originalView.bottom);
    }];
    [self.contentView makeConstraints:^(MASConstraintMaker *make) {
        
        make.bottom.equalTo(toolBar.bottom);
        make.top.leading.trailing.equalTo(self);
    }];
}
@end
